package com.incar.chuxing.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import com.incar.chuxing.utils.SharedPreferencesUtils;

import java.io.File;

/**
 * Created by user1 on 2017/4/26.
 */

public class NotificationClickReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String filePath = intent.getStringExtra("filePath");
        installAPK(filePath, context);
    }

    private void installAPK(String filePath, Context context) {
        File apkfile = new File(filePath);
        if (apkfile.exists()) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            Uri apkFileUri = Uri.fromFile(apkfile);
            intent.setDataAndType(apkFileUri, "application/vnd.android.package-archive");
            context.startActivity(intent);
            SharedPreferencesUtils.getInstance(context).removeValue("downloadId");
        }

    }
}
